/**
 * Created by Administrator on 2015/12/22.
 */
/**
 * Created by Administrator on 2015/12/3.
 */
"use strict";
var _o2oServiceApi = require('../../../common/o2oServiceApi');
var o2oServiceApi = new _o2oServiceApi;
var F = require('../../../common/function');
let ware_F = require('./ware_common');
var _ = require('underscore');

exports.wareListForVendorDetail = function *(obj_query){
  let ret = yield this.commonWareList(obj_query);
  if(ret.error_msg !=''){
    return F.returnMsg(300, ret.error_msg, 1,ret.data);
  }else{
    for(let i in ret.data.list){
      ret.data.list[i]=ware_F.warePropertyForList(ret.data.list[i]);
    }
    return F.returnMsg(200, '成功', 1, ret.data);
  }
};

exports.wareAuditList = function *(obj_query){
  let ret = yield this.commonWareList(obj_query);
  if(ret.error_msg !=''){
    return F.returnMsg(300, ret.error_msg, 1,ret.data);
  }else{
    return F.returnMsg(200, '成功', 1, ret.data);
  }
};
exports.wareHistoryList = function *(obj_query){
  let ret = yield this.commonWareList(obj_query);
  if(ret.error_msg !=''){
    return F.returnMsg(300, ret.error_msg, 1,ret.data);
  }else{
    return F.returnMsg(200, '成功', 1, ret.data);
  }
};

exports.wareDeleteList = function *(obj_query){
  let ret = yield this.commonWareList(obj_query);
  if(ret.error_msg !=''){
    return F.returnMsg(300, ret.error_msg, 1,ret.data);
  }else{
    return F.returnMsg(200, '成功', 1, ret.data);
  }
};

exports.commonWareList = function *(obj_query) {
  let ret = {error_msg: '',data:[]};
  let wareList = yield o2oServiceApi.post('ware', 'listVersion', 1, obj_query);
  if (parseInt(wareList['result']['error']) == 1 || wareList.status == 400) {
    ret.error_msg = wareList['message']['msg'];
  } else {
    if (_.isEmpty(wareList['result']['list']) || wareList['result'].count == undefined) {
      ret.error_msg = '没有数据';
    } else {
      ret.data = wareList['result'];
    }
  }
  return ret;
};